package com.edu.juc.threadPool;

import java.util.concurrent.*;

public class SubmitCommit {
    public static void main(String[] args) {
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(2, 5, 1000, TimeUnit.MINUTES, new ArrayBlockingQueue<>(10), new ThreadPoolExecutor.AbortPolicy());

        FutureTask<String> futureTask = new FutureTask<>(() -> {
            System.out.println(Thread.currentThread().getName() + "子线程开始执行");
            Thread.sleep(3000);
            System.out.println(Thread.currentThread().getName() + "子线程执行完毕");
            return "子线程执行完毕";
        });
        threadPoolExecutor.execute(futureTask);
        Future<?> submit = threadPoolExecutor.submit(futureTask);
//        threadPoolExecutor.execute(futureTask);

        try {
            System.out.println(submit.get());
        } catch (InterruptedException | ExecutionException e) {
            throw new RuntimeException(e);
        }


//        try {
//            TimeUnit.SECONDS.sleep(5);
//        } catch (InterruptedException e) {
//            throw new RuntimeException(e);
//        }

        threadPoolExecutor.shutdown();
    }
}
